package LinkList;

import java.util.HashMap;
import java.util.LinkedHashMap;

public class item160 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
       if(headA==null||headB==null) return null;
        HashMap<ListNode,Integer> map = new LinkedHashMap<>();
        ListNode cur = headA;
        while (cur!=null)
        {
            map.put(cur, cur.val);
            cur = cur.next;
        }
        ListNode curB = headB;
        boolean flag = false;
        while (curB!=null)
        {
            if(map.containsKey(curB))
            {
                flag = true;
                break;
            }
            curB = curB.next;
        }
        if(flag==true) return curB;
        else
        return null;
    }
}
